package net.wanho.personalOffice.dao.impl;

import net.wanho.commons.exception.DaoException;
import net.wanho.commons.exception.DataAccessException;
import net.wanho.commons.factory.BeanFactory;
import net.wanho.commons.util.JDBCTemplate;
import net.wanho.customerManage.po.LinkMan;
import net.wanho.personalOffice.dao.IndividualTaskDao;
import net.wanho.personalOffice.po.IndividualTask;

import java.util.List;

public class IndividualTaskDaoImpl implements IndividualTaskDao {
    private JDBCTemplate jdbcTemplate = BeanFactory.getBean(JDBCTemplate.class) ;
    @Override
    public List<IndividualTask> selectIndividualTaskByEmployeeId(Integer employeeId) throws DaoException {
        final String SELECT_INDIVIDUAL_TASK_BY_EMPLOYEE_ID_SQL = "SELECT \t\n" +
                "\tTASK_ID TASKID, \n" +
                "\tTOPIC TOPIC, \n" +
                "\tDESCRIPTION DESCRIPTION, \n" +
                "\tRESPONSIBLE_PERSON RESPONSIBLEPERSON, \n" +
                "\tEND_TIME ENDTIME, \n" +
                "\tPRIORITY PRIORITY, \n" +
                "\tSTATUS STATUS, \n" +
                "\tCREATE_TIME CREATETIME, \n" +
                "\tOPERATOR OPERATOR, \n" +
                "\tLINK_URL LINKURL, \n" +
                "\tTASK_TYPE TASKTYPE\n" +
                "\tFROM \n" +
                "individual_task \n" +
                "   WHERE\n" +
                "   RESPONSIBLE_PERSON = ? \n" +
                "OR\n" +
                "   task_id IN (SELECT DISTINCT TASK_ID FROM task_user_relations WHERE EMPLOYEE_ID=?)\n" +
                "ORDER BY\n" +
                "   PRIORITY DESC " ;
        try {
            Object[] params = {employeeId,employeeId} ;
            return jdbcTemplate.queryForList(SELECT_INDIVIDUAL_TASK_BY_EMPLOYEE_ID_SQL, IndividualTask.class,params);
        } catch (DataAccessException e) {
            e.printStackTrace();
            throw new DaoException(e.getMessage()) ;
        }
    }
}
